<?php

namespace app\admin\controller\xuboss;

use app\common\controller\Backend;
use think\Session;

class Menu extends Backend
{
    protected $searchFields = 'id,name';
    /**
     * @var mixed|string
     */
    private $service_secret;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('xuboss.menu');
        $this->service_secret = Session::get('admin')['secret'];
        if (empty($this->service_secret))
            $this->service_secret = "Jp)GuX=M^KthZV7^";
        if (!empty(Session::get('admin')['secret'])) {
            $this->model
                ->where(['service_secret' => $this->service_secret]);
        }
    }
    public function store_list(){
        //设置过滤方法
        $data = $this->request->param();
        list($where, $sort, $order, $offset, $limit) = $this->buildparams();
        if (!empty($data['searchKey']))
            $where = [$data['searchKey']=>$data['searchValue']];
        $list = $this->model
            ->where($where)
            ->where(['service_secret'=>$this->service_secret])
            ->order($sort, $order)
            ->paginate($limit);
        $result = array("total" => $list->total(), "rows" => $list->items());
        return json($result);
    }
}